import { showTimeNotSecond } from '@/libs/utils';
export default {
    name: 'cardRender',
    functional: true,
    props: {
        row: Object,
        render: Function,
        index: Number,
        column: {
            type: Object,
            default: null
        },
        type: String
    },
    render: (h, { props, listeners, data }) => {
        props.row._index = props.index;
        const params = {
            row: props.row,
            index: props.index
        };
        if (props.column) params.column = props.column;
        let getCellContent = data.attrs.getCellContent;
        function getColor(column, row) {
            return typeof column.setColor === 'function'
                ? column.setColor(row[column.key], row)
                : column.setColor
                ? column.setColor
                : '';
        }
        if (props.column.type === 'render') {
            return props.render(h, params);
        } else if (
            props.column.type === 'href' &&
            (!props.column.disabled || !props.column.disabled(props.row)) &&
            getCellContent(props.column, props.row) != '-'
        ) {
            return h(
                'a',
                {
                    class: {
                        'text-ellipsis': props.column.tooltip,
                        pointer: props.column.fun
                    },
                    attrs: {
                        href:
                            (props.column.setPath && props.column.setPath(props.row)) ||
                            'javascript:void(0)'
                    },
                    on: {
                        click: () => {
                            props.column.fun && props.type !== 'content'
                                ? props.column.fun(props.row)
                                : '';
                        },
                        ...listeners
                    }
                },
                getCellContent(props.column, props.row)
            );
        } else if (props.column.type === 'Tag' && props.type !== 'content') {
            let color = getColor(props.column, props.row);
            return h(
                'Tag',
                {
                    class: {
                        'text-ellipsis': props.column.tooltip,
                        pointer: props.column.fun
                    },
                    props: {
                        type: 'border',
                        color: color || 'var(--url-color)'
                    },
                    nativeOn: {
                        click: () => {
                            return props.column.fun && props.type !== 'content'
                                ? props.column.fun(props.row)
                                : '';
                        }
                    }
                },
                getCellContent(props.column, props.row)
            );
        } else if (props.column.type === 'Html') {
            let content = props.row[props.column.key];
            if (props.column.filter) {
                content = props.column.filter(content);
            }
            return h('span', {
                domProps: {
                    innerHTML: props.type === 'content' ? content : content.replace(/\<br\>/g, '')
                },
                attrs: {
                    title: props.column.fun && !props.column.tooltip ? '点击查看' : ''
                },
                class: {
                    'blue-color': props.type === 'content' ? false : true,
                    'html-ellipsis': props.type === 'content' ? false : true,
                    'text-ellipsis': props.type === 'content' ? false : true,
                    pointer: props.column.fun && props.type !== 'content' ? true : false
                },
                style: {
                    color: props.column.fun && props.type !== 'content' ? 'var(--url-color)' : ''
                },
                on: {
                    click: () => {
                        return props.column.fun && props.type !== 'content'
                            ? props.column.fun(props.row)
                            : '';
                    },
                    ...listeners
                }
            });
        } else {
            let color = getColor(props.column, props.row);
            let content = getCellContent(props.column, props.row);
            return h(
                'span',
                {
                    class: props.column.tooltip ? 'ivu-table-cell-tooltip-content' : '',
                    style: {
                        color: props.type !== 'content' ? color : ''
                    },
                    on: {
                        ...listeners
                    }
                },
                content
            );
        }
    }
};
